package com.feel.service.impl;

import com.feel.mapper.AppointmentMapper;
import com.feel.pojo.Appointment;
import com.feel.service.AppointmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 刘永钦
 * @Date: 2024-09-04-16:41
 * @Description:
 */
@Service
public class AppointmentServiceImpl implements AppointmentService {
    @Autowired
    private AppointmentMapper appointmentMapper;

    @Override
    public PageInfo<Appointment> getAll(Integer page, Appointment appointment) {
        PageHelper.startPage(page, 5);
        List<Appointment> list = appointmentMapper.getAll(appointment);
        PageInfo<Appointment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Boolean updateInfo(Appointment appointment) {
        if (appointment.getEmpId() != null) {
            if (appointment.getAppointmentStatus() == 0) {
                appointment.setAppointmentStatus(2);
                appointment.setSpeed("1");
            }
        }
        Integer i = appointmentMapper.updateInfo(appointment);
        return i > 0;
    }

    @Override
    public Boolean delInfo(Integer id) {
        Integer i = appointmentMapper.delInfo(id);
        return i > 0;
    }

    @Override
    public Appointment getById(Integer id) {
        Appointment appointment = appointmentMapper.getById(id);
        return appointment;
    }

    @Override
    public Boolean addInfo(Appointment appointment) {
        Integer i = appointmentMapper.addInfo(appointment);
        return i > 0;
    }

    @Override
    public Integer getAppointmentNumber() {
        List<Appointment> list = appointmentMapper.getAll(null);
        return list.size();
    }
}
